package com.drink.yan.web.rest;

import com.drink.yan.intf.define.YanActivityStatusE;
import com.drink.yan.intf.entity.YanActivity;
import com.drink.yan.intf.entity.YanActivityUser;
import com.drink.yan.intf.entity.YanSku;
import com.drink.yan.intf.vo.ActivityVo;
import com.drink.yan.job.YanActivityStatusJob;
import com.drink.yan.svc.service.YanActivityService;
import com.drink.yan.web.rest.req.cmd.ApplyActivityCmd;
import com.drink.yan.web.rest.req.cmd.CancelActivityCmd;
import com.drink.yan.web.rest.req.qry.PageActivityQry;
import com.meta.act.app.service.ISysNoticeService;
import com.meta.framework.common.annotation.Log;
import com.meta.framework.common.core.controller.BaseController;
import com.meta.framework.common.core.page.TableDataInfo;
import com.meta.framework.common.core.page.TableResponseVo;
import com.meta.framework.common.enums.BusinessType;
import com.meta.framework.common.utils.SecurityUtils;
import com.meta.framework.core.CommonRes;
import com.meta.framework.core.ResponseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * java类简单作用描述
 *
 * @Title:
 * @Package: com.drink.yan.web.rest.app.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2023/11/23 14:58
 * @Version: v2.0
 */
@RestController
@RequestMapping("/activity")
public class ActivityRest extends BaseController {

    private ISysNoticeService noticeService;

    @Resource
    private YanActivityService yanActivityService;

    @Resource
    private YanActivityStatusJob yanActivityStatusJob;

    @ApiOperation(value = "获取活动", notes = "获取活动", tags = {"学生小程序"})
    @GetMapping("/list")
    public TableResponseVo<List<ActivityVo>> listActivity(PageActivityQry pageActivityQry){
        if("hot".equals(pageActivityQry.getQueryType())){
            pageActivityQry.setPageSize(2);
            pageActivityQry.setActivityStatusList(YanActivityStatusE.effective());
        }
        startPage();
        List<ActivityVo> list = yanActivityService.listActivity(pageActivityQry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "活动报名", notes = "活动报名", tags = {"学生小程序"})
    @PostMapping("/apply")
    public ResponseVo<ActivityVo> applyActivity(@RequestBody ApplyActivityCmd cmd){

        if(Objects.isNull(cmd.getUserId())){
            cmd.setUserId(SecurityUtils.getUserId());
        }
        return ResponseVo.success(yanActivityService.applyActivity(cmd));
    }

    @ApiOperation(value = "活动签到", notes = "活动签到", tags = {"学生小程序"})
    @PostMapping("/sign")
    public ResponseVo<ActivityVo> signActivity(@RequestBody ApplyActivityCmd cmd){

        if(Objects.isNull(cmd.getUserId())){
            cmd.setUserId(SecurityUtils.getUserId());
        }
        return ResponseVo.success(yanActivityService.signActivity(cmd));
    }

    @ApiOperation(value = "活动详情", notes = "活动详情", tags = {"学生小程序"})
    @GetMapping("/detail/{activityId}")
    public ResponseVo<ActivityVo> detail(@PathVariable Long activityId){

        return ResponseVo.success(yanActivityService.getActivityDetail(activityId));
    }


    @ApiOperation(value = "保存活动", notes = "保存活动", tags = {"PC"})
    @PostMapping("/save")
    public ResponseVo<YanActivity> saveActivity(@RequestBody YanActivity yanActivity){
        return ResponseVo.success(yanActivityService.saveActivity(yanActivity));
    }

    @ApiOperation(value = "取消活动", notes = "取消活动", tags = {"PC"})
    @PostMapping("/cancel")
    public ResponseVo<Object> cancelActivity(@RequestBody CancelActivityCmd cmd){
        return ResponseVo.success(yanActivityService.cancelActivity(cmd));
    }

    @ApiOperation(value = "删除活动", notes = "删除活动", tags = {"PC"})
    @DeleteMapping("/delete/{activityId}")
    public ResponseVo<Object> deleteSku(@PathVariable("activityId") Long activityId){
        return ResponseVo.success(yanActivityService.deleteActivity(activityId));
    }

    @ApiOperation(value = "test", notes = "test", tags = {"PC"})
    @DeleteMapping("/test")
    public ResponseVo<Object> test(){
        yanActivityStatusJob.handle();
        return ResponseVo.success(true);
    }
}
